﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using MyOA.Model;

namespace MyOA.DAL
{
    public class FileLeftService
    {
        DBHelper db = new DBHelper();

        /// <summary>
        /// 根据是否删除来获取文件信息
        /// </summary>
        /// <param name="ifDelete">是否删除</param>
        /// <returns>文件信息</returns>
        public IList<FileInfo> getFileInfoByIfDelete(int ifDelete)
        {
            IList<FileInfo> fileInfos = new List<FileInfo>();
            using (SqlDataReader reader = db.getDataReader("sp_getFileInfoByIfDelete", new SqlParameter("@ifDelete", ifDelete)))
            {
                while (reader.Read())
                {
                    FileInfo fileInfo = new FileInfo();
                    fileInfo.FileId = (int)reader[0];
                    fileInfo.FilesName = (string)reader[1];
                    fileInfo.Remark = (string)reader[2];
                    fileInfo.CreateDate = (DateTime)reader[3];
                    fileInfo.ParentId = (int)reader[4];
                    fileInfo.FilePath = (string)reader[5];
                    fileInfo.FileType.FileTypeId = (int)reader[6];
                    fileInfo.FileOwner.UserId = (int)reader[7];
                    fileInfo.FileType.FileTypeName = (string)reader[8];
                    fileInfo.FileType.FileTypeImage = (string)reader[9];
                    fileInfo.FileType.FileTypeSuffix = (string)reader[10];
                    fileInfo.FileOwner.LoginId = (string)reader[11];
                    fileInfo.FileOwner.UserName = (string)reader[12];
                    fileInfo.FileOwner.Role.RoleId = (int)reader[13];
                    fileInfo.FileOwner.Depart.DepartId = (int)reader[14];
                    fileInfo.FileOwner.UserState.UserStateId = (int)reader[15];
                    fileInfo.FileOwner.Role.RoleName = (string)reader[16];
                    fileInfo.FileOwner.Depart.DepartName = (string)reader[17];
                    fileInfo.FileOwner.Depart.Branch.BranchId = (int)reader[18];
                    fileInfo.FileOwner.Depart.Branch.BranchName = (string)reader[19];
                    fileInfo.FileOwner.Depart.Branch.BranchShortName = (string)reader[20];
                    fileInfos.Add(fileInfo);
                }
            }
            db.CloseConnection();
            return fileInfos;
        }
        /// <summary>
        /// 根据parentId来获取文件信息
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns>文件信息</returns>
        public IList<FileInfo> getFileInfoByParentId(int parentId)
        {
            IList<FileInfo> fileInfos = new List<FileInfo>();
            using (SqlDataReader reader = db.getDataReader("sp_getFileInfoByParentId", new SqlParameter("@parentId", parentId)))
            {
                while (reader.Read())
                {
                    FileInfo fileInfo = new FileInfo();
                    fileInfo.FileId = (int)reader[0];
                    fileInfo.FilesName = (string)reader[1];
                    fileInfo.ParentId = (int)reader[2];
                    fileInfo.FileType.FileTypeImage = (string)reader[3];
                    fileInfos.Add(fileInfo);
                }
            }
            db.CloseConnection();
            return fileInfos;
        }
    }
}
